package cn.zn.modules.expense.controller;

import cn.hutool.core.util.StrUtil;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.expense.service.TpMainService;
import cn.zn.modules.expense.vo.ExpenseForMoney;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author zn
 * @email zhunahao@qq.com
 * @date 2019-12-29 22:42:32
 */
@RestController
@RequestMapping("api/apply")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class TpMainOldController {
    final private TpMainService tpMainService;

    @GetMapping("moneyOccupyDetail")
    @ResponseBody
    public R moneyOccupyDetail(String moneyTypeCode, String projectCode, String cateCode) throws IOException {
        List<ExpenseForMoney> list = tpMainService.findByMoney(moneyTypeCode, projectCode, cateCode);
        return R.ok().put("list", list);
    }

    @GetMapping("findTaskInfo")
    @ResponseBody
    public R findTaskInfo(String taskId) throws IOException {
        if (!StrUtil.isNotBlank(taskId)) {
            return R.error("taskId 不能为空").put("success", false);
        }
        return R.ok().put("success", true).put("data", tpMainService.findTaskInfo(taskId));
    }

    @PostMapping("findTaskInfos")
    @ResponseBody
    public R findTaskInfos(String taskIds) throws IOException {
        if (!StrUtil.isNotBlank(taskIds)) {
            return R.error("taskIds 不能为空").put("success", false);
        }
        String[] taskIdArr = taskIds.split(",");
        if (taskIdArr.length == 0) {
            return R.error("taskIds 不能为空").put("success", false);
        }
        return R.ok().put("success", true).put("data", tpMainService.findTaskInfos(Lists.asList(new String(), taskIdArr)));
    }

}
